import { Inject } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { ArticleInfoEntity } from '../../entity/info';
import { ArticleInfoService } from '../../service/info';
import { Get } from '@midwayjs/core';
import { Context } from '@midwayjs/koa';

/**
 * 客户端文章接口
 */
@CoolController({
  api: ['info', 'list', 'page'],
  entity: ArticleInfoEntity,
  service: ArticleInfoService,
})
export class AppArticleInfoController extends BaseController {
  @Inject()
  articleInfoService: ArticleInfoService;

  @Inject()
  ctx: Context;

  @Get('/view', { summary: '查看帖子' })
  async view() {
    const { id } = this.ctx.request.query;
    await this.articleInfoService.view(Number(id));
    return this.ok();
  }

  @Get('/like', { summary: '点赞帖子' })
  async like() {
    const { id } = this.ctx.request.query;
    await this.articleInfoService.like(Number(id));
    return this.ok();
  }
}
